#ifndef SL_CONVERT_HPP
#define SL_CONVERT_HPP

// std Header
#include <string>
#include <sstream>
#include <exception>

namespace sl
{
	template <class L, class R>
	R Convert(const L& lhs)
	{
		std::stringstream stream;
		stream << lhs;

		R rhs;

		try
		{
			stream >> rhs;
		}
		catch (std::exception& e)
		{
			throw e;
		}

		return rhs;
	}

	template <class L, class R>
	R Convert(const L& lhs, R& rhs)
	{
		rhs = Convert<L, R>(lhs);
		return rhs;
	}

	template <class L, class R>
	R Convert(const L& lhs, const R& rhs)
	{
		return Convert<L, R>(lhs);
	}

	template <class L>
	std::string Convert(const L& lhs)
	{
		return Convert<L, std::string>(lhs, std::string());
	}

	/*template <class D>
	D* Default(D* var, D* opt)
	{
		if (var == 0)
			return opt;

		return var;
	}*/

	bool Default(bool var, bool opt);
	double Default(double var, double opt);
	float Default(float var, float opt);
	int Default(int var, int opt);
	std::string Default(const std::string& var, const std::string& opt);

	std::string GetNameFromFilename(const std::string& filename);

	unsigned int ConvertHex(const std::string& hex);
	std::string ConvertToHex(unsigned int hex);
}

#endif //SL_CONVERT_HPP